package com.banciyuan.bcywebview.biz.topic;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.daoexample.model.Special;

/**
 * Created by squall on 2015/8/14.
 */
public class TopicDetailFootAdapter extends BaseAdapter {

    private List<Special> slist=new ArrayList<Special>();

    private Context mContext;

    private LayoutInflater inflater;

    public TopicDetailFootAdapter(List<Special> slist,Context mContext){
        this.slist=slist;
        this.mContext=mContext;
        this.inflater=LayoutInflater.from(mContext);
    }


    @Override
    public int getCount() {
        return slist.size();
    }

    @Override
    public Object getItem(int i) {
        return slist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    private class ViewHolder{
        TextView title;
        ImageView pic;

        public ViewHolder(View convertView){
            pic= (ImageView) convertView.findViewById(R.id.topic_footer_img);
            title= (TextView) convertView.findViewById(R.id.topic_footer_title);
        }
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder=null;
        if(view==null){
            view=inflater.inflate(R.layout.topic_list_footer_item,null);
            viewHolder=new ViewHolder(view);
            view.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }

        Special s=slist.get(i);
        ImageLoader.getInstance().displayImage(s.getCover_link(),viewHolder.pic, ImageOptions.options);
        viewHolder.title.setText(Html.fromHtml(s.getTitle()));
        return view;
    }
}
